package com.xiaren.util;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.JTextPane;
import javax.swing.text.AttributeSet;
import javax.swing.text.Document;
import javax.swing.text.EditorKit;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.StyledEditorKit;
import com.xiaren.common.ObjectConstant;
import com.xiaren.ui.edit.FileEdit;

/**
 * @主页 http://www.leaf123.cn/
 * @邮箱 xia5523@qq.com
 */
public class FontSizeComboBox extends JComboBox {
	public static final String[] ARRAY_FONT_SIZE = { "12", "14", "18", "20",
			"22" };

	private FileEdit fileedit;

	public FontSizeComboBox() {
		super(ARRAY_FONT_SIZE);
		this.setSize(30, 30);
		this.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				FontSizeComboBox source = (FontSizeComboBox) e.getSource();
				Object value = source.getSelectedItem();
				fileedit = (FileEdit) ObjectConstant.mainEdit
						.getSelectedComponent();
				if(fileedit == null){
					return;
				}
				MutableAttributeSet attr = new SimpleAttributeSet();
				StyleConstants.setFontSize(attr,
						Integer.parseInt(value.toString()));
				StyledEditorUtil.setCharacterAttributes(
						(JEditorPane) fileedit.getTypeFile(), attr, false);
				source.setSelectedIndex(0);
			}
		});
	}

}
